import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';
import 'package:widget_example/sample/tag_sample.dart';

import 'button_sample.dart';
import 'empty_sample.dart';
import 'search_sample.dart';
import 'styles.dart';

/// add new src.sample route here
var routes = {
  ButtonSample.routeName: (_) => ButtonSample(),
  EmptySample.routeName: (_) => EmptySample(),
  SearchSample.routeName: (_) => SearchSample(),
  TagSample.routeName: (_) => const TagSample(),
};

class WidgetsSample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return WidgetTheme(
      data: Themes.widgetThemeData,
      child: MaterialApp(
        theme: Themes.appTheme,
        home: MyHome(),
        routes: routes,
      ),
    );
  }
}

class MyHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const CommonAppBar(
        titleData: 'Widget Samples',
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Wrap(
          spacing: 10,
          children: <Widget>[
            ...routes.entries
                .toList()
                .map((e) => _buildRaisedButton(context, e.key))
          ],
        ),
      ),
    );
  }

  Widget _buildRaisedButton(BuildContext context, String routeName) {
    return ElevatedButton(
      onPressed: () {
        Navigator.pushNamed(context, routeName);
      },
      child: Text(routeName),
    );
  }
}
